package com.example.wananrdroid.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.wananrdroid.R;
import com.example.wananrdroid.adapter.Vpadapter;
import com.example.wananrdroid.fragment.zhufragment.HomeFragment;
import com.example.wananrdroid.fragment.zhufragment.TixiFragment;
import com.example.wananrdroid.fragment.zhufragment.WenFragment;
import com.example.wananrdroid.fragment.zhufragment.WoFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

/**
 * A simple {@link Fragment} subclass.
 */
public class ZhuFragment extends Fragment {


    private ViewPager mZhuVp;
    private TabLayout mZhuTab;

    public ZhuFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_zhu, container, false);
        initViews(view);
        return view;
    }

    private void initViews(View view) {
        mZhuVp = view.findViewById(R.id.zhu_vp);
        mZhuTab = view.findViewById(R.id.zhu_tab);
        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(new HomeFragment());
        fragments.add(new WenFragment());
        fragments.add(new TixiFragment());
        fragments.add(new WoFragment());
        Vpadapter vpadapter = new Vpadapter(getChildFragmentManager(), fragments);
        mZhuVp.setAdapter(vpadapter);
        mZhuTab.setupWithViewPager(mZhuVp);
        inittab();
    }

    private void inittab() {
        mZhuTab.getTabAt(0).setText("首页").setIcon(R.drawable.home1);
        mZhuTab.getTabAt(1).setText("问答").setIcon(R.drawable.chat1);
        mZhuTab.getTabAt(2).setText("体系").setIcon(R.drawable.list);
        mZhuTab.getTabAt(3).setText("我的").setIcon(R.drawable.me1);
    }
}
